/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cis36_gardengame;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;

/**
 *TopLevel holds the base modules and implements the ActionListener for passing 
 *user parameters between the UI panel and the board object
 * @author Jonah
 */
public class TopLevel implements ActionListener{

    /**
     *Constructor for TopLevel objects, takes in default parameters 
     */
    public TopLevel() {
        board = new Board( 
                    new BoardState(
                        20, //pixels
                        24, //columns
                        24, //rows
                        12, //rocks
                        12, //flowers
                        12, //bugs
                        6   //critters
                    )
                );
        //ui = new UI();
        //the ActionListener lets the button objects call methods from within
        //TopLevel.java or any of its subobjects.
        //ui.getjButton1().addActionListener(this);
        //ui.getjButton2().addActionListener(this);
        
    }
    
    @Override
    public void actionPerformed( ActionEvent e) {
        if (e.getSource().equals(ui.getjButton1())) {
            passNewBoardState();
        }
        if (e.getSource().equals(ui.getjButton2())) {
            passIterations();
        }
    }
    
    /**
     * gets the values from the ui panel and passes them to the game object
     */
    private void passNewBoardState(){
        BoardState bs = new BoardState(
                (int)ui.getjSpinner1().getValue(),//pixels
                (int)ui.getjSpinner3().getValue(),//columns
                (int)ui.getjSpinner2().getValue(),//rows
                (int)ui.getjSpinner4().getValue(),//rocks
                (int)ui.getjSpinner5().getValue(),//flowers
                (int)ui.getjSpinner6().getValue(),//bugs
                (int)ui.getjSpinner7().getValue() //critters
                );
        System.out.println("passing BoardState:");
        System.out.println(bs.toString());
        
        board.newGame(bs);
    }
    /**
     * gets only the iteration value from the ui panel and passes it to the game 
     * object
     */
    private void passIterations(){
        board.runGame((int)ui.getjSpinner8().getValue());
    }
    
    //top most parent objects
    public JFrame frame;
    public Board board;
    private UI ui;
}
